<?php
/**
 * GioCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@ninhgio.com so we can send you a copy immediately.
 * 
 * @copyright	Copyright (c) 2010-2011 GioCMS (http://cms.ninhgio.com)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @author		NinhGio - ninhgio@gmail.com
 * @since		1.0
 */
?>
<div class="g_a_ui_cycle" id="gCoreWidgetToolbox">
	<div class="g_a_ui_cycle_header">
		<!-- Prev button -->
		<a href="javascript: void(0);" id="gCoreWidgetToolboxModulePrev" class="g_a_ui_cycle_prev">prev</a>
		
		<!-- List of modules -->
		<div class="g_a_ui_cycle_tabs">
		<?php foreach ($this->modules as $index => $module) : ?>
			<?php if ($index % 3 == 0) : ?>
			<ul>
			<?php endif; ?>
			
			<li><a class="g_a_tip_top" href="javascript: void(0);" rel="<?php echo $module['module_id']; ?>" title="<?php echo $this->TRANSLATOR->translator('about_' . $module['module_id'] . '_title', $module['module_id']); ?>"><img src="<?php echo sprintf('%s/modules/%s/configs/thumbnails/thumbnail_48.png', $this->APP_WEB_URL, $module['module_id']); ?>" width="48" height="48" /><br /><b><?php echo $this->TRANSLATOR->translator('about_' . $module['module_id'] . '_title', $module['module_id']); ?></b></a></li>
			
			<?php if (($index % 3 == 2) || $index == count($this->modules) - 1) : ?>
			</ul>
			<?php endif; ?>
		<?php endforeach; ?>
		</div>
		
		<!-- Next button -->
		<a href="javascript: void(0);" id="gCoreWidgetToolboxModuleNext" class="g_a_ui_cycle_next">next</a>
		<div class="clear"></div>
	</div>
	<div class="g_a_line"></div>
	<div class="clear"></div>
	<div class="g_a_ui_cycle_content" id="gCoreWidgetToolboxContent"></div>
	<div class="clear"></div>
</div>
<script type="text/javascript">
$(document).ready(function() {
	var s  = document.createElement('script');
	s.type = 'text/javascript';
	s.text  = '$(\'<script type="text\/javascript" src="<?php echo $this->APP_STATIC_SERVER; ?>\/js\/jquery.cycle\/jquery.cycle.all.js"><\/script>\').appendTo(\'body\');';
	document.body.appendChild(s);

	$('#gCoreWidgetToolbox .g_a_ui_cycle_tabs')
		.cycle({
			fx: 'scrollHorz',
		    timeout: 0,
			prev: '#gCoreWidgetToolboxModulePrev',
			next: '#gCoreWidgetToolboxModuleNext'
		})
		.find('a').click(function() {
			$('#gCoreWidgetToolboxContent').addClass('g_a_ajax_loading');
			var params = 'mod=' + $(this).attr('rel');
			$('#gCoreWidgetToolbox .g_a_ui_cycle_header_active').removeClass('g_a_ui_cycle_header_active');
			$(this).parents('li').addClass('g_a_ui_cycle_header_active');
			Gio.Core.Widget.Loader.queueAction('core', 'widgettoolbox', 'load', params, $('#gCoreWidgetToolboxContent'), function(response) {
				$('#gCoreWidgetToolboxContent').removeClass('g_a_ajax_loading');
			});
		});
	$('#gCoreWidgetToolbox .g_a_ui_cycle_tabs a:first').click();
	
	/**
	 * Make the textbox, textarea, WYSIWYG editors droppable
	 */
	$('.g_a_widget_dropped').each(function() {
		$(this).droppable({
			activeClass: 'g_a_widget_dropped_active',
			hoverClass: 'g_a_widget_dropped_hover',
			drop: function(event, ui) {
				if (!$(ui.helper).hasClass('g_core_widgettoolbox_draggable')) {
					return;
				}
				Gio.Core.Widget.index++;
				
				var self = this;
				var blockname = null;
				blockname = $(self).parents('.col').find('.g_a_blockname:first').text();
				$(self).addClass('g_a_ajax_loading');				
				var data = $(ui.helper).attr('id');
				data = data.split('_');
				var params = 'route=<?php echo $this->route; ?>|widget_index=' + Gio.Core.Widget.index;
				Gio.Core.Widget.Loader.queueAction(data[0], data[1], 'config', params, null, function(response) {
					configString = (response == '') ? '' : '<li><?php echo $this->TRANSLATOR->widget('config_title'); ?><br />' + response + '</li>';
					var string = '<ul>'
						+ configString
						+ '<li><?php echo $this->TRANSLATOR->widget('config_load_by_ajax'); ?> <input type="checkbox" name="blocks[' + Gio.Core.Widget.index + '][load]" value="ajax" /></li>'
						+ '<li><?php echo $this->TRANSLATOR->widget('config_cache_use'); ?> <input type="checkbox" name="blocks[' + Gio.Core.Widget.index + '][cache][enable]" value="true" /></li>'
						+ '<li><?php echo $this->TRANSLATOR->widget('config_cache_timeout'); ?><br /> <input type="text" class="text" name="blocks[' + Gio.Core.Widget.index + '][cache][timeout]" value="0" style="width: 60px; margin-top: 5px;" /></li>'
						+ '<li><?php echo $this->TRANSLATOR->translator('common_config_invisible'); ?> <input type="checkbox" name="blocks[' + Gio.Core.Widget.index + '][visible]" value="false" /></li>'
						+ '</ul>'
						+ '<div class="clear">'
						+ '<p class="last buttons_demo">'
						+ '<a href="javascript: void(0);" onclick="javascript: $(this).parents(\'.g_a_widget_dropped\').html(\'<p><?php echo $this->TRANSLATOR->translator('common_no_data'); ?><p>\');" class="button red"><small class="icon cross"></small><span><?php echo $this->TRANSLATOR->translator('common_button_delete'); ?></span></a>'
						+ '</p>'
						+ '</div><div class="clear"></div>'
						+ '<input type="hidden" name="blocks[' + Gio.Core.Widget.index + '][block_name]" value="' + blockname + '">';
					$(self).html(string);
					$(self).removeClass('g_a_ajax_loading');
				});
			}
		});
	});
});
</script>